<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<div id="app">
			<h2>{{message}}</h2>
			<h2>{{info.name}}</h2>
			<button @click="changeMsg">修改</button>
		</div>

		<script src="./js/vue.js"></script>
		<script>
			// 1. 创建app实例
			const app = Vue.createApp({
				data() {
					return {
						message: 'hello vue',
						info: {
							name: '张三',
							age: 12,
						},
					}
				},
				methods: {
					changeMsg() {
						this.message = 'abc'
						this.info.name = '李四'
					},
				},
				// 默认watch不会进行深度监听的
				watch: {
					info: {
						handler(newVal, oldVal) {
							console.log('newVal, oldVal: ', newVal, oldVal)
							console.log(newVal === oldVal)
						},
						deep: true,
						// 第一次也执行watch
						immediate: true,
					},
					'info.name': {
						handler(newVal, oldVal) {
							console.log('newVal, oldVal: ', newVal, oldVal)
						},
					},
				},
			})

			// 2. 挂载到#app上
			app.mount('#app')
		</script>
	</body>
</html>
